﻿<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="../css/show.css" rel="stylesheet" type="text/css" />
      <script src="../js/jquery-1.11.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/commen_js/jquery.cookie.min.js"></script>
    <script src="../../Scripts/layer-v1.9.3/layer/layer.js"></script>
    <script src="../../Scripts/commen_js/json2.js"></script>
     <script src="../js/MJ_JSComment_two.js"></script>
    <script title="javascript">
        $(document).ready(function () {
            var code = GetQueryString("code");
            //获取openid
            poststr = "{\"type\":\"getopenid\",\"code\":\"" + code + "\"}";
            mj_js_ajax("json", poststr, getopenid);
        })
        var building_drom = "";
        //根据openid获取套餐
        function getopenid(data) {
            if (data.result == "ok") {
                //"omnZ1s0LocHW6xMfltqkA1SdFoHo"
                var openids = data.msg;
                //openids = "orG7TvgK244wWkqAGkC0URXg56Lg";
                if (isUndefinedNullOrEmpty(openids)) {
                    layer.alert("系统繁忙请稍候再试！", {
                        icon: 0,
                        skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅

                    })
                    return;
                }
                getrecord(openids);
            }
            else {
                layer.alert(data.msg, {
                        icon: 0,
                        skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅

                    })
            }
        }
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        //根据openid获取套餐
        function getrecord(openid) {
            poststr = "{\"type\":\"getuser_record\",\"code\":\"" + openid + "\"}";
            mj_js_ajax("json", poststr, shouresult);
        }

        var ask_type = 1;//1是套餐列表有的2是没有的。这个是叫水类型，分有套餐列表里面有的和套餐列表没有的
        //套餐列表没有的但是叫水记录里面有的而且是2的（就是新套餐的）
        function shouresult(data) {
            if (data.result == "ok") {
                var record_askwater_data = data.record_askwater;
                var taocanlist_data = data.taocanlist;
                if (taocanlist_data.length != 0) {
                    $("#brand").text("品牌：" + $.trim(taocanlist_data[0].brand).replace("A套餐", "").replace("B套餐", "").replace("C套餐", "").replace("D套餐", "")); 
                    $("#remarks").text("剩余：" + $.trim(taocanlist_data[0].shengyu_tongshu));
                    $("#qiantong_shu").text("欠桶数：" + $.trim(taocanlist_data[0].qiantong));
                    $("#sushe").text("宿舍：" + $.trim(taocanlist_data[0].Louhao) + "-" + $.trim(taocanlist_data[0].sushe_number));
                    building_drom = taocanlist_data[0].Louhao + "|" + taocanlist_data[0].sushe_number;
                    var table = document.getElementById("record");
                    $("#record").empty();
                    for (var i in record_askwater_data) {
                        if (record_askwater_data[i].songshui_tongshu == "0") {
                             continue; 
                        }
                    var tr = document.createElement("tr");
                    var td1 = document.createElement("td");
                    td1.innerHTML = record_askwater_data[i].ask_watertime;
                    var td2 = document.createElement("td");
                    td2.innerHTML = record_askwater_data[i].songshui_tongshu;
                    var td3 = document.createElement("td");
                    td3.innerHTML = record_askwater_data[i].huishou_tongshu == null ? "" : record_askwater_data[i].huishou_tongshu;
                    var td4 = document.createElement("td");
                    td4.innerHTML = record_askwater_data[i].state == 0 ? "已送" : record_askwater_data[i].state == 1 ? "未送" : record_askwater_data[i].state == 2 ? "在送" : "";
                   
                    tr.appendChild(td1);
                    tr.appendChild(td2);
                    tr.appendChild(td3);
                    tr.appendChild(td4);
                    table.appendChild(tr);
                    }
                }
                else if (record_askwater_data.length != 0) {
                    try{
                        var have_new_water = "no";
                        var brand="";
                        var sushe = "";
                        var table = document.getElementById("record");
                        $("#record").empty();
                        for (var i in record_askwater_data)
                        {
                            if (record_askwater_data[i].delect == 2) {
                                brand = $.trim(record_askwater_data[i].brand).replace("A套餐", "").replace("B套餐", "").replace("C套餐", "").replace("D套餐", "");
                                have_new_water = "yes";
                                ask_type = 2;
                                building_drom = record_askwater_data[i].Louhao + "|" + record_askwater_data[i].sushe_number;
                                sushe = "宿舍：" + $.trim(record_askwater_data[i].Louhao) + "-" + $.trim(record_askwater_data[i].sushe_number);
                            }
                            else {
                                    var tr = document.createElement("tr");
                                    var td1 = document.createElement("td");
                                    td1.innerHTML = record_askwater_data[i].ask_watertime;
                                    var td2 = document.createElement("td");
                                    td2.innerHTML = record_askwater_data[i].songshui_tongshu;
                                    var td3 = document.createElement("td");
                                    td3.innerHTML = record_askwater_data[i].huishou_tongshu == null ? "" : record_askwater_data[i].huishou_tongshu;
                                    var td4 = document.createElement("td");
                                    td4.innerHTML = record_askwater_data[i].state == 0 ? "已送" : record_askwater_data[i].state == 1 ? "未送" : record_askwater_data[i].state == 2 ? "在送" : "";

                                    tr.appendChild(td1);
                                    tr.appendChild(td2);
                                    tr.appendChild(td3);
                                    tr.appendChild(td4);
                                    table.appendChild(tr);
                            }
                        }
                        if (have_new_water == "no") {
                            $("#tips").text("你绑定的宿舍现在已经送完，请重新订购套餐");
                        }
                        else {
                            $("#brand").text("品牌：" + brand);
                            $("#remarks").text("剩余：" + "0");
                            $("#qiantong_shu").text("欠桶数：" + "0");
                            $("#sushe").text(sushe);

                        }
                    }
                    catch(e){}
                }
                else {
                    $("#tips").text("你绑定的宿舍现在没有订购任何套餐！");
                }
            }
            else {
                $("#tips").text(data.msg);
            }

        }

        function ask_water() {
            var tongshu = $.trim($("#send_amount").val());
            var huishoutongshu = $.trim($("#huishoutongshu").val());

            //var tongshu = parseInt();
            if (tongshu == "" || tongshu == null) {

                layer.alert("叫水桶数不能为空", {
                    icon: 0,
                    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                   
                })
                return;
            }
            else if (parseInt(tongshu) == 0) {
                layer.alert("叫水桶数不能0", {
                    icon: 0,
                    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                })
                return;
            }
            else if (parseInt(tongshu) > 3) {
                layer.alert("叫水桶数不能超过3桶", {
                    icon: 0,
                    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                })
                return;
            }
            else if (huishoutongshu == "") {
                layer.alert("预计回收桶数不能为空", {
                    icon: 0,
                    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                })
                return;
            }
            var remark = $.trim($("#remark").val());
            poststr = "{\"type\":\"userask_water\",\"code\":\"" + tongshu.toString() + "|" + remark + "|" + building_drom + "|" + huishoutongshu + "|" + ask_type + "\"}";
            mj_js_ajax("json", poststr, show);
        }
        function show(data) {
            if (data.result == "ok") {
                alert(data.msg);
                shouresult(data);
            }
            else { alert(data.msg)}

        }

        function showmore() {
            if (building_drom == "") {

            }

            else {
                poststr = "{\"type\":\"showmore_askwater\",\"code\":\""+building_drom+"\"}";
                mj_js_ajax("json", poststr, showin);
            }

        }
        function showin(data) {


            if (data.result == "ok") {
                var record_askwater_data = data.record_askwater;
                if (record_askwater_data.length != 0) {
                    var table = document.getElementById("record");
                    $("#record").empty();
                    for (var i in record_askwater_data) {
                        var tr = document.createElement("tr");
                        var td1 = document.createElement("td");
                        td1.innerHTML = record_askwater_data[i].ask_watertime;
                        var td2 = document.createElement("td");
                        td2.innerHTML = record_askwater_data[i].songshui_tongshu;
                        var td3 = document.createElement("td");
                        td3.innerHTML = record_askwater_data[i].huishou_tongshu == null ? "" : record_askwater_data[i].huishou_tongshu;
                        var td4 = document.createElement("td");
                        td4.innerHTML = record_askwater_data[i].state == 0 ? "已送" : record_askwater_data[i].state == 1 ? "未送" : record_askwater_data[i].state == 2 ? "在送" : "";

                        tr.appendChild(td1);
                        tr.appendChild(td2);
                        tr.appendChild(td3);
                        tr.appendChild(td4);
                        table.appendChild(tr);
                    }
                }
                else {
                    
                }
            }
            else { }

        }
    </script>
    <title>叫水及查询</title>
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <h2 class="text-center text-info">
                邑大水行一键叫水</h2>
            <hr />
            <div class="col-xs-6 col-xs-offset-0">
                <div class="input-group">
                    <label for="send_amount" class="sr-only">
                        桶数</label><input class="form-control" style="border-color:#5CACEE" id="send_amount" type="text" placeholder="叫水桶数"></div>
            </div>
            <div class="col-xs-6" style="padding-left: 0;">
                <div class="input-group">
                    <label for="remark" class="sr-only">
                        预计回桶数</label><input class="form-control" style="border-color:#5CACEE"  id="huishoutongshu" type="text" placeholder="预计回桶数"></div>
            </div>
        </div>

        <div class="row" style="margin-top:13px">
           <div class="col-xs-6  col-xs-offset-0" >
                <div class="input-group">
                    <label for="remark" class="sr-only">
                        备注</label><input class="form-control" style="border-color:#5CACEE"  id="remark" type="text" placeholder="备注"></div>
            </div>
            <div class="col-xs-6" style="padding-left: 0;">
                        <input onclick="ask_water()" type="button"  value="叫水" id="call" class="btn btn-primary btn-block">
                            </div>
        </div>
        <!--<br/>-->
        <div class="text-center" id="tips" style="color: red; margin-top:5px">
        </div>
        <div class="row">
            <div class="col-xs-12 text-success text-center" style="font-size: 50px; color: #00FF80;">
            </div>
        </div>
        <div class="row">
             <div id="sushe" style="padding:0px" class="col-xs-6  text-center">
                宿舍：无</div>
            <div id="brand" style="padding:0px; padding-left:6px" class="col-xs-6 text-center">
                品牌：无</div>
           
           
        </div>
        <div>
             <div id="remarks" class="col-xs-6 text-center" style="padding:0px 0px">
                剩余：0</div>
             <div id="qiantong_shu" class="col-xs-6 text-center" style="padding:0px 0px">
                欠桶：0</div>
        </div>
        <hr style=" margin-top:5px" />
        <div class="row">
            <h3 class="text-center text-primary" style="margin-top: 0;">
                送水记录</h3>
            <div class="col-xs-12">
                <table class="table table-bordered table-striped" style="border-radius:5px; " id="table">
                    <thead>
                        <tr>
                            <th>
                                日期  
                            </th>
                            <th>
                                桶数
                            </th>
                            <th>
                                回桶
                            </th>
                            <th style="text-align: center">
                                状态
                            </th>
                        </tr>
                    </thead>
                    <tbody id="record">
                    </tbody>
                </table>
                <div id="next" style=" margin-left:75%">
                    <button class="btn btn-primary" onclick="showmore()" value="2">
                        加载更多</button></div>
            </div>
        </div>
    </div>
</body>
</html>
